package com.wt.wechatTools.room.dao;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.wt.wechatTools.room.entity.ContactsEntity;

import java.util.List;
//参考https://blog.csdn.net/wuditwj/article/details/84388354
@Dao   //Database access object
public interface ContactsDao {
    /**
     * 插入
     * @param contactsEntities
     */
    @Insert
    void insert(ContactsEntity... contactsEntities);

    @Insert
    void insertList(List<ContactsEntity> contactsEntities);

    @Update
    void update(ContactsEntity... contactsEntities);

    @Update
    void updateList(List<ContactsEntity> contactsEntities);

    /**
     * 删除数据
     * @param contactsEntities
     */
    @Delete
    void  delete(ContactsEntity... contactsEntities);

    /**
     * 获取所有数据
     * @return
     */
    @Query("SELECT * FROM ContactsEntity")
    LiveData<List<ContactsEntity>> getAllLive();

    /**
     * 获取所有名单数据
     * @return
     */
    @Query("SELECT * FROM ContactsEntity")
    List<ContactsEntity> getAll();

    /**
     * 获取不包含未使用状态的名单数据
     * @return
     */
    @Query("SELECT * FROM ContactsEntity where state != 1")
    List<ContactsEntity> get();

    /**
     * 删除所有数据
     */
    @Query("DELETE FROM CONTACTSENTITY")
    void   deleteAll();

    /**
     * 获取制定定个数的未使用 手机号
     * @param count
     * @return
     */
    @Query("SELECT * FROM ContactsEntity WHERE state = 1 LIMIT :count")
    List<ContactsEntity> getByCount(Integer count);

    /**
     * 获取制定定个数的未使用 手机号
     * @param count
     * @return
     */
    @Query("SELECT * FROM ContactsEntity WHERE state = 5 LIMIT :count")
    List<ContactsEntity> getState5(Integer count);

    //获取第一行数据
    @Query("SELECT * FROM ContactsEntity LIMIT 1")
    ContactsEntity getFirst();

    /**
     * 根据手机号查询
     * @param cellPhone
     * @return
     */
    @Query("SELECT * FROM ContactsEntity WHERE cellPhone= :cellPhone")
    ContactsEntity getContactsByCellPhone(String cellPhone);

    /**
     * 根据状态查询手机号
     * @param state
     * @return
     */
    @Query("SELECT * FROM ContactsEntity WHERE state= :state")
    LiveData<List<ContactsEntity>> getContactsByStateLife(Integer state);

    /**
     * 根据状态查询手机号
     * @param state
     * @return
     */
    @Query("SELECT * FROM ContactsEntity  WHERE state= :state LIMIT 50")
    List<ContactsEntity> getContactsByState(Integer state);

    /**
     * 查询 状态 2和3（已执行和无法查找）
     * @return
     */
    @Query("SELECT * FROM ContactsEntity WHERE state= 3 or state = 2")
    LiveData<List<ContactsEntity>> getContactsBy2and3Life();

    /**
     * 根据任务批次查询数据
     * @return
     */
    @Query("SELECT * FROM ContactsEntity WHERE tastBatch = :batch")
    List<ContactsEntity> getContactsByTastBatch(Integer batch);

    /**
     * 根据任务批次查询数据
     * @return
     */
    @Query("SELECT * FROM ContactsEntity WHERE tastBatch = :batch")
    LiveData<List<ContactsEntity>> getContactsByTastBatchLive(Integer batch);
}

